/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package servidor;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author javi
 */
public class Servidor implements Runnable {

    private ServerSocket servidor;
    private Socket cliente;
    private String path;
    
    public Servidor(int puerto, String path) throws IOException {
        servidor = new ServerSocket(puerto);
        this.path = path;
    }

    public void aceptarConexion() {
        try {
            cliente = servidor.accept();
            System.out.println("Conectado un cliente");
            new Thread(new ControladorClientes(cliente, path)).start();
        } catch (IOException ex) {
            Logger.getLogger(Servidor.class.getName()).log(Level.SEVERE, null, ex);
        }
    }

    @Override
    public void run() {
        while (true) {
            aceptarConexion();
        }
    }
}
